import util from "@/libs/util";
import { dateRangeValide } from "@/libs/validator/function";

import iview from 'view-design';



export const queryAndReset = {
  methods: {
    // 查询
    formQuery() {
      const keys = [["startDate","endDate"],["bgnTime","endTime"],["startTime","endTime"],["bgnDate","endDate"]]
    //   Object.keys(this.formItem).forEach(item => {
    //    this.listQuery[item] = this.formItem[item];
    //  });
     let days = 0
     for(const key in this.formItem) {
       if(this.formItem[key]===0) {
        this.listQuery[key] = null
       }else{

       this.listQuery[key] = this.formItem[key];
      }
       keys.some(v=>{
         if(v[0]===key) {
          days = dateRangeValide(this.formItem[v[0]],this.formItem[v[1]],30)
          return true
         }
       })
     }
     
     if(days==='1') return this.$Message.warning("开始/起始时间大于结束/截止时间")
     // if(days==='2') return this.$Message.warning("由于数据量大时间范围不能大于30天")
     // if(days==='3') return this.$Message.warning("请输入开始/起始时间、结束/截止时间")
    //  if(days==='4') return this.$Message.warning("结束/截止时间不能大于今天")

     this.tablePageData = {
       pageNum: 1,
       pageSize: this.listQuery.pageSize
     }
     // this.initTable();
   },

   //重置
   formReset() {
    const keys = [["startDate","endDate"],["bgnTime","endTime"],["startTime","endTime"],["bgnDate","endDate"]]
     Object.keys(this.formItem).forEach(item => {
       
       this.formItem[item] = "";
       this.listQuery[item] = "";
       if(item==='areaNo' || item==='orgNo') {
        this.formItem[item] = null
       }
       if(this.custInfo.custId&&item==='siteId') {
        this.formItem[item] = this.$options.data().formItem[item]
       }
       keys.some(v=>{
         if(v[0]===item) {
          this.formItem[v[0]] = this.$options.data().formItem[v[0]]
          this.formItem[v[1]] = this.$options.data().formItem[v[1]]
          return true
         }
       })
     });
     
     this.tablePageData.pageNum = 1
   },
   areaChange(val) {
    this.formItem.custNo = ""
    this.dicData.custName = []
    this.getCBaseInfoListByCliqueId(val.id)
  },
  }
}
